package com.lam.dormitory.common.quartz;

import com.alibaba.excel.EasyExcel;
import com.lam.dormitory.common.easyExcel.DormitoryServiceVoListener;
import com.lam.dormitory.service.IDormitoryServiceService;
import com.lam.dormitory.vo.DormitoryServiceVo;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@PersistJobDataAfterExecution
@DisallowConcurrentExecution
@Component
//@PersistJobDataAfterExecution和@DisallowConcurrentExecution注解是不让某个定时任务并发执行，只有等当前任务完成下一个任务才会去执行。
public class JobOne implements Job {
    @Autowired
    private IDormitoryServiceService dormitoryServiceService;
    @Value("${easyexcel.path}")
    private String path;

    //定期插入数据库
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        EasyExcel.read(path, DormitoryServiceVo.class, new DormitoryServiceVoListener(dormitoryServiceService)).sheet().doRead();
    }
}